package tw.raybird.walker.officereader;

import java.io.File;
import java.io.InputStream;

import org.apache.log4j.Logger;
import org.apache.poi.POITextExtractor;
import org.apache.poi.extractor.ExtractorFactory;

public class MSOfficeReader implements Reader{

	private Logger logger;
	
	public MSOfficeReader(){
		logger = Logger.getRootLogger();
	}
	
	@Override
	public String read(File file) {
		String content = "";
		POITextExtractor extractor;
		try {
			extractor = ExtractorFactory.createExtractor(file);
			content = extractor.getText();
		} catch (Exception e) {
			logger.warn("", e);
		} 
		extractor = null;
		return content;			
	}
	
	public String read(InputStream inputStream){
		String content = "";
		POITextExtractor extractor;
		try {
			extractor = ExtractorFactory.createExtractor(inputStream);
			content = extractor.getText();
		} catch (Exception e) {
			logger.warn("", e);
		} 
		extractor = null;
		return content;		
	}
}
